<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>92Play后台管理</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/managercss.css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/validate.js"></script>
<script type="text/javascript">
	var ctp = '<%=request.getContextPath() %>';
	$(function(){
			
		$("#productId").val('${billing.productId}');
		$("#billingType").val('${billing.billingType}');
		if($("#spendLimit").val()!=0){
			$("#ulSpendLimit").show();
		}else{
			$("#ulSpendLimit").hide();
		}
		
		if($("#days").val()!=0){
			$("#ulDays").show();
		}else{
			$("#ulDays").hide();
		}

		if($("#periodHour").val()!=0){
			$("#ulPeriodHour").show();
		}else{
			$("#ulPeriodHour").hide();
		}
		
		$("#tipType").val('${billing.tipType}');

		if($("#tipMessage").val()!=''){
			$("#ulTipMessage").show();
			if($("#tipType").val()==2 || $("#tipType").val()==4 || $("#tipType").val()==5 ){
				$("#ulConfirmTimes").show();
			}
		}else{
			$("#ulTipMessage").hide();
		}

		$("#userType").val('${billing.userType}');
		
		$("#update").click(function(){
			var billingName = $("#billingName").val();
			var fee = $("#fee").val();
			var billingType = $("#billingType").val();
			var tipType = $("#tipType").val();
			var spendLimit = $("#spendLimit").val();
			var days = $("#days").val();
			var tipMessage = $("#tipMessage").val();
			var periodHour = $("#periodHour").val();
			if(isNull(billingName)){
				alert("请输入计费点名称!");
				$("#billingName").focus();
				return;
			}else if(isNull(fee)||!isNum(fee)){
				alert("请输入正确的资费!");
				$("#fee").focus();
				return;
			}else if(billingType==0&&(isNull(spendLimit)||!isNum(spendLimit))){
				alert("请输入正确的消费上限!");
				$("#spendLimit").focus();
				return;
			}else if(billingType==1 &&(isNull(days) || !isNum(days))){
				alert("请输入正确的计费天数!");
				$("#days").focus();
				return;
			}else if(billingType==1 &&(isNull(spendLimit)||!isNum(spendLimit))){
				alert("请输入正确的消费上限!");
				$("#spendLimit").focus();
				return;
			}else if(tipType!=0 && isNull(tipMessage)){
				alert("请输入提示信息!");
				$("#tipMessage").focus();
				return;
			}else if(tipType==2 && (isNull(periodHour) || !isNum(periodHour))){
				alert("请输入正确的有效天数!");
				$("#periodHour").focus();
				return;
			}else{
				var date = $("#billingForm").formSerialize();
				$.ajax({
					url:ctp+"/admin/billing/update",
					data:date,
					type:"POST",
					success:function(flag){
						if(flag=='1'){
							alert("修改成功!");
							 parent.location.reload();
							//window.location.href="<%=request.getContextPath() %>/admin/billing/list?productId="+$('#productId').val()+"&userType="+$('#userType').val();
						}else{
							alert("修改失败!");
						}
					}
				});
				return;
			}
		});

		$("#billingType").change(function(){
			if($(this).val()==0){//点播
				$("#ulSpendLimit").show();//显示消费上限
				$("#ulDays").hide();//隐藏包天数
				$("#days").val('');
			}else if($(this).val()==1){//假包月
				$("#ulSpendLimit").show();//显示消费上限
				$("#ulDays").show();//显示包天数
			}else{//包月
				$("#ulSpendLimit").hide();//隐藏消费上限
				$("#spendLimit").val('');
				$("#ulDays").hide();//隐藏包天数
				$("#days").val('');
			}
		});

		$("#tipType").change(function(){
			if($(this).val()==0){
				$("#ulTipMessage").hide();
				$("#tipMessage").val('');
				$("#ulPeriodHour").hide();
				$("#periodHour").val('');
				$("#ulConfirmTimes").hide();
				$("#confirmTimes").val('');
			}else if($(this).val()==1){
				$("#ulTipMessage").show();
				$("#ulPeriodHour").hide();
				$("#periodHour").val('');
				$("#ulConfirmTimes").hide();
				$("#confirmTimes").val('');
			}else if($(this).val()==2){
				$("#ulTipMessage").show();
				$("#ulPeriodHour").show();
				$("#ulConfirmTimes").show();
			}else if($(this).val()==3){
				$("#ulTipMessage").show();
				$("#ulPeriodHour").hide();
				$("#periodHour").val('');
				$("#ulConfirmTimes").hide();
				$("#confirmTimes").val('');
			}else if($(this).val()==4){
				$("#ulTipMessage").show();
				$("#ulPeriodHour").hide();
				$("#periodHour").val('');
				$("#ulConfirmTimes").show();
			}else{
				$("#ulTipMessage").show();
				$("#ulPeriodHour").hide();
				$("#periodHour").val('');
				$("#ulConfirmTimes").show();
			}
		});
	});
</script>
</head>
<body>
<div class="information">
	<div class="list">
		<form method="post" id="billingForm">
		<input type="hidden" name="billingId" id="billingId" value="${billing.billingId }">
		<div class="noselect">
			<ul>
				<li style="width: 100px;text-align: right;">产品：</li>
				<li style="width: 300px;text-align: left;">
					<select name="productId" id="productId" style="width: 150px;">
						<c:forEach items="${productList}" var="product">
							<option value="${product.productId }">${product.productName }</option>
						</c:forEach>
					</select>
				</li>
			</ul>
			<div class="clear"></div>
			<ul>
				<li style="width: 100px;text-align: right;">计费点名称：</li>
				<li style="width: 300px;text-align: left;">
					<input type="text" name="billingName" id="billingName" value="${billing.billingName }" size="40"></input>
				</li>
			</ul>
			<div class="clear"></div>
			<ul>
				<li style="width: 100px;text-align: right;">资费：</li>
				<li style="width: 300px;text-align: left;">
					<input type="text" name="fee" id="fee" value="${billing.fee }" size="20"/>元
				</li>
			</ul>
			
			<div class="clear"></div>
			<ul>
				<li style="width: 100px;text-align: right;">计费类型：</li>
				<li style="width: 300px;text-align: left;">
					<select name="billingType" id="billingType" style="width: 150px;">
						<option value="0">点播</option>
						<option value="1">假包月</option>
						<option value="2">包月</option>
					</select>
				</li>
			</ul>
			<div class="clear"></div>
			<ul id="ulSpendLimit">
				<li style="width: 100px;text-align: right;">消费上限：</li>
				<li style="width: 300px;text-align: left;">
					<input type="text" name="spendLimit" id="spendLimit" value="${billing.spendLimit }" size="20">元
				</li>
			</ul>
			<div class="clear"></div>
			<ul style="display: none;" id="ulDays">
				<li style="width: 100px;text-align: right;">天数：</li>
				<li style="width: 300px;text-align: left;">
					<input type="text" name="days" id="days" value="${billing.days}" size="20">天
				</li>
			</ul>
			<div class="clear"></div>
			<ul>
				<li style="width: 100px;text-align: right;">提示类型：</li>
				<li style="width: 300px;text-align: left;">
					<select name="tipType" id="tipType" style="width: 150px;">
						<option value="0">不提示 </option>
						<option value="1">每次都提示</option>
						<option value="2">只首次提示</option>
						<option value="3">确认型</option>
						<option value="4">确认超时型</option>
						<option value="5">确认取消型</option>
					</select>
				</li>
			</ul>
			<div class="clear"></div>
			<ul style="display: none;" id="ulPeriodHour">
				<li style="width: 100px;text-align: right;">提示有效天数：</li>
				<li style="width: 300px;text-align: left;">
					<input type="text" name="periodHour" id="periodHour" value="${billing.periodHour }" size="20">天
				</li>
			</ul>
			<div class="clear"></div>
			<ul style="display: none;" id="ulConfirmTimes">
				<li style="width: 100px;text-align: right;">超时秒数：</li>
				<li style="width: 300px;text-align: left;">
					<input type="text" name="confirmTimes" id="confirmTimes" size="20" value="${billing.confirmTimes }">秒
				</li>
			</ul>
			<div class="clear"></div>
			<ul style="display: none;" id="ulTipMessage">
				<li style="width: 100px;text-align: right;">提示信息：</li>
				<li style="width: 300px;text-align: left;">
					<textarea name="tipMessage" id="tipMessage" cols="40" rows="5">${billing.tipMessage }</textarea>
				</li>
			</ul>
			<div class="clear"></div>
			<ul>
				<li style="width: 100px;text-align: right;">用户类型：</li>
				<li style="width: 300px;text-align: left;">
					<select name="userType" id="userType" style="width: 150px;">
						<option value="0">白名单 </option>
						<option value="1">灰名单</option>
						<option value="2">黑名单</option>
					</select>
				</li>
			</ul>
			<div class="clear"></div>
			<ul>
				<li style="width: 100px;text-align: right;">备注：</li>
				<li style="width: 300px;text-align: left;">
					<textarea name="memo" id="memo" cols="40" rows="5">${billing.memo }</textarea>
				</li>
			</ul>
			<div class="clear"></div>
			<ul>
				<li style="width: 100px;text-align: right;">&nbsp;</li>
				<li style="width: 300px;text-align: left;">
					<input type="button" id="update" value="提 交" /> 
				</li>
			</ul>
			<div class="clear"></div>
		</div>
		</form>
	</div>
</div>
</body>
</html>